<!--
 * @Description: 历史调整信息
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2022-01-05 17:47:39
 * @LastEditTime: 2023-05-11 14:52:14
 * @FilePath: \cscec-pms-admin\src\views\construction\constructionScheduleAdjust\components\HistoryAdjust.vue
-->
<template>
  <BaseModal
    :visible="visible"
    title="历史调整信息"
    :width="GET_REDRESS_PERCENTAGE * 0.8 +'vw'"
    destroy-on-close
    :wrap-class-name="'history-adjust'"
    @cancel="handleModalCancel"
  >
    <b-table
      ref="table"
      :scroll="data.nodeType === 0?{}:{ x: 2840 }"
      :columns="columns"
      :request="loadData"
      bordered
      :is-show-total="false"
      :show-page="false"
      row-key="id"
    />
    <template slot="footer">
      <a-button @click="handleModalCancel">
        关闭
      </a-button>
    </template>
  </BaseModal>
</template>
<script>
import BaseModal from '@/components/BaseModal'
import { columns1 } from '../model.js'
import { view } from '@/api/construction/constructionScheduleAdjust'
import { mapGetters } from 'vuex'
export default {
  name: 'HistoryAdjust',
  props: {
    isAudit: {
      // 是否作为审批详情
      type: Boolean,
      default: false
    },
    // 隐藏显示
    visible: {
      type: Boolean,
      require: true
    },
    // 节点信息
    data: {
      type: Object,
      require: true
    }
  },
  components: {
    BaseModal
  },
  data() {
    return {
      // 表头源数据
      columns1,
      // 表格数据加载
      loadData: async (q) => {
        try {
          const res = await view.queryHistoryAdjustDtail(this.data.id)
          if (res.code === 200) {
            return res
          } else {
            return { code: 200, data: [] }
          }
        } catch (error) {
          console.log(error)
          return { code: 200, data: [] }
        }
      }
    }
  },
  computed: {
    ...mapGetters(['GET_REDRESS_PERCENTAGE']),
    // 表头
    columns() {
      if (this.data.nodeType === 0) {
        return [
          {
            title: '序号',
            width: 100,
            align: 'center',
            customRender: (text, record, index) => {
              return index + 1
            }
          },
          {
            title: '阶段/类别',
            dataIndex: 'phaseCategory'
          }
        ]
      } else {
        const list = ['sortNum', 'phaseCategory']
        const col = this.$clone(this.columns1)
          .filter((el) => {
            if (!list.includes(el.dataIndex)) {
              return el
            }
          })
          .map((el) => {
            // if (el.dataIndex === 'controlLevelId') {
            //   el.dataIndex = 'controlLevelName'
            //   return el
            // } else if (el.dataIndex === 'directResPerList') {
            //   el.customRender = (text) => {
            //     return text.map((el) => el.label).join(',')
            //   }
            //   return el
            // } else {
            //   return el
            // }
            switch (el.dataIndex) {
              case 'controlLevelId': {
                el.dataIndex = 'controlLevelName'
                return el
              }
              case 'directResPerList': {
                el.customRender = (text) => {
                  return text.map((el) => el.label).join(',')
                }
                return el
              }
              case 'isKeyNode':
              case 'isMilestonesNode':
              case 'isMainProcessNode':
              case 'isVerticalTransportNode':
              case 'isContractDurationNode': {
                el.customRender = (text) => {
                  return text ? '是' : '否'
                }
                return el
              }
              default: {
                return el
              }
            }
          })
        col.unshift({
          title: '序号',
          width: 100,
          align: 'center',
          customRender: (text, record, index) => {
            return index + 1
          }
        })
        return col
      }
    }
  },
  methods: {
    /**
     * @description: 关闭模态框
     * @param {boolean} 是否需要刷新
     * @return {void}
     */
    handleModalCancel(refresh = false) {
      this.$emit('update:visible', false)
      if (refresh) {
        this.$emit('refresh', true)
      }
    }
  }
}
</script>
<style lang="less" scoped>
.history-adjust {
  height: calc(var(--heightVh) * 0.6);
  overflow-y: auto;
  padding-right: 10px;
}
</style>
